#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string s;
int n;
void print()
{
	cout << s << endl;
}
void fun1()
{
	string temp;
	cin >> temp;
	s += temp;
}
void fun2()
{
	int a, b;
	cin >> a >> b;
	string temp;
	int count = 0;
	for (int i = a ; i < s.size(); i++) {
		temp += s[i];
		count++;
		if (count == b) {
			break;
		}
	}
	s = temp;
}

int main()
{
	cin >> n;
	getchar();
	getline(cin, s);
	while (n--) {
		string temp;
		cin >> temp;
		if (temp[0] == '1') {
			fun1();
			print();
		}
		else if (temp[0] == '2') {
			fun2();
			print();
		}
		else if (temp[0] == '3') {
			string t;
			int a;
			cin >> a >> t;
			s = s.insert(a, t);
			print();
		}
		else {
			string t;
			cin >> t;
			cout << s.find(t) << endl;
		}
	}
	return 0;
}